package com.cssnj.portal.service.query;

import io.predictech.framework.domain.common.JsonRequest;
import io.predictech.framework.domain.common.JsonResponse;
import io.predictech.framework.domain.exception.BaseException;
import io.predictech.framework.service.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service("query02Service")
public class Query02Service  extends BaseService {

    @Qualifier("fourthJdbcTemplate")
    @Autowired
    private JdbcTemplate fourthJdbcTemplate;

    @Override
    protected JsonResponse invokingService(JsonRequest jsonRequest) throws SQLException, BaseException {
        switch (jsonRequest.getHandleCode()) {
            case "queryData":
                return queryData(jsonRequest);
        }
        return null;
    }

    protected JsonResponse queryData(JsonRequest jsonRequest) {
        JsonResponse jsonResponse = new JsonResponse();
        String swjgdm = (String)jsonRequest.getReqData().get("swjgdm");
        List<Object> params = new ArrayList<Object>();
        params.add(swjgdm);
        List<Map<String, Object>> dataList = queryDao.queryForList(fourthJdbcTemplate," SELECT A_HS,B_HS,C_HS,D_HS,M_HS FROM CX_QYXYPDQK WHERE SWJG_DM = ? ",params);
        if(dataList.size()>0){
            jsonResponse.getRepData().put("data", dataList.get(0));
        }
        return jsonResponse;
    }

}
